package com.lhf.smallClass.controller;

import com.lhf.smallClass.model.SmallClass;
import com.lhf.smallClass.model.SmallClassVo;
import com.lhf.smallClass.service.SmallClassService;
import com.lhf.util.ResultBuliderVo;
import com.lhf.util.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author 尐痞猫
 * @date2021-06-23 17:22
 */
@RestController
@RequestMapping("/smallClass")
@Slf4j
public class SmallClassController {

    @Autowired
    private SmallClassService smallClassService;
    //分页查询
    @PostMapping("/queryPage")
    public ResultVo queryPage(@RequestBody SmallClassVo smallClassVo) {
        return smallClassService.queryPage(smallClassVo);
    }

    @PostMapping("/add")
    public ResultVo add(@RequestBody @Valid SmallClass smallClass,BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            return ResultBuliderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return smallClassService.add(smallClass);
    }

    @GetMapping("/queryById")
    public ResultVo queryById(Integer id){
        return smallClassService.queryById(id);
    }

    @PostMapping("/update")
    public ResultVo update(@RequestBody SmallClass smallClass){
      return  smallClassService.update(smallClass);
    }

    @PostMapping("/legalpersonStatus")
    public ResultVo legalpersonStatus(@RequestBody SmallClass smallClass){
       return smallClassService.updateByStatus(smallClass);
    }

    @GetMapping("/queryByStatus")
    public ResultVo queryByStatus(Integer status){
        return smallClassService.queryByStatus(status);
    }

    @GetMapping("/getStatus")
    public ResultVo getStatus(){
        return smallClassService.queryAllStatus();
    }



}
